package com.ln.lnzw.adapter;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.blankj.utilcode.util.ActivityUtils;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.ln.lnzw.R;
import com.ln.lnzw.activity.HandleaffairsServiceFormsActivity;
import com.ln.lnzw.bean.Level0Item;
import com.ln.lnzw.bean.Level1Item;

import java.util.List;

/**
 * Created by luoxw on 2016/8/9.
 */
public class ConsultationDepartmentMattersAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    private static final String TAG = ConsultationDepartmentMattersAdapter.class.getSimpleName();

    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;
    private ClickMyItem onClickMyItem;
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ConsultationDepartmentMattersAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.item_three_one);
        addItemType(TYPE_LEVEL_1, R.layout.item_three_two);
    }


    @Override
    protected void convert(final BaseViewHolder holder, final MultiItemEntity item) {
        switch (holder.getItemViewType()) {
            case TYPE_LEVEL_0:
                final Level0Item lv0 = (Level0Item) item;
                holder.setText(R.id.tv_name, lv0.title).setText(R.id.tv_type,"职权类型："+lv0.ql_kind).setText(R.id.tv_implementation,"实施主体："+lv0.idorg);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getAdapterPosition();
                        Log.d(TAG, "Level 0 item pos: " + pos);


                        if (lv0.isExpanded()) {
                            collapse(pos);
                        } else {
                            expand(pos);
//                            }
                        }
                    }
                });
                break;
            case TYPE_LEVEL_1:
                final Level1Item lv1 = (Level1Item) item;
                holder.setText(R.id.text, lv1.title);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Log.i("123", "onClick: "+"指南");
                        onClickMyItem.onClickMyItem(v,lv1.title,lv1.itemCode);
//                        Log.i("123", "itemId: "+lv1.itemId);
//                        Bundle b  = new Bundle();
//                        b.putString("itemId",lv1.itemId);
//                        ActivityUtils.startActivity(b,HandleaffairsServiceFormsActivity.class);
                    }
                });
                break;

        }
    }

    //接口回调
    public interface ClickMyItem{
        public void onClickMyItem(View v,String name,String itemCode);
    }
    public void setonClickMyItem(ClickMyItem onClickMyItem) {
        this.onClickMyItem = onClickMyItem;
    }

}
